﻿// <copyright file="CoverageCloud.aspx.cs">
// Copyright (c) 2009 All Right Reserved
// </copyright>
// <author>Yuvaraj Ilangovan</author>
// <date>2009-07-14</date>
// <summary>Contains UI logic for showing cloud report</summary>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RepRef;
using System.Configuration;

public partial class ContentPages_CoverageCloud : System.Web.UI.Page
{
    RepRef.IsimpleWcfClient aggrProxy;

    StatisticsReport ststReport;
    ModuleManager mgr;
    string strXMLPath;

    public string ProjectName
    {
        get
        {
            string _projName = string.Empty;
            if (Session["ProjName"] != null)
            {
                _projName = Convert.ToString(Session["ProjName"]);
            }
            else
            {
                _projName = ConfigurationManager.AppSettings["ProjName"].ToString();
            }
            return _projName;
        }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        lblprojName.Text = this.ProjectName; 
        if (Session["RptXMLPath"] != null)
        {
            strXMLPath = Session["RptXMLPath"].ToString();
        }
        //if (Request.QueryString != null)
        //{
        //    string modname = Request.QueryString["modname"].ToString();
        //    string rptLink = Request.QueryString["rptLink"].ToString(); 
        //}       

        if (!string.IsNullOrEmpty(Request.QueryString.ToString()))
        {
            
            if (!string.IsNullOrEmpty(Request.QueryString["nName"]) && !string.IsNullOrEmpty(Request.QueryString["mod1"]))
            {
                LoadNamesLevelStatistics(Request.QueryString["mod1"].ToString(), Request.QueryString["nName"].ToString(), strXMLPath);
            }
            else if (!string.IsNullOrEmpty(Request.QueryString["nName"]) && !string.IsNullOrEmpty(Request.QueryString["modname"]))
            {
                LoadNamesLevelStatistics(Request.QueryString["modname"].ToString(), Request.QueryString["nName"].ToString(), strXMLPath);
            }
            else if (!string.IsNullOrEmpty(Request.QueryString["modname"]))
            {
                LoadModLevelStastistics(Request.QueryString["modname"].ToString(), strXMLPath);
            }
            else
            {
                LoadApplicationStatistics(strXMLPath);
            }
        }
        

       
    }

    protected void LoadApplicationStatistics(string strXMLPath)
    {
        try
        {
            aggrProxy = new IsimpleWcfClient();
            mgr = aggrProxy.ParseXmlObject(strXMLPath);
            ststReport = aggrProxy.GetStatetics(strXMLPath);           
            lblCovLines.Text = ststReport.LOC.ToString();
            lblParCovLines.Text = ststReport.PLOC.ToString();
            //lblCovClasses.Text = ststReport.
            lblCovBlocks.Text = ststReport.BlocksCov.ToString();
            lblNCLines.Text = ststReport.NCLOC.ToString();
            lblNCBlocks.Text = ststReport.BlocksNt.ToString();
            lblStatsName.Text = this.ProjectName;
            lblCovClasses.Text = mgr.CoveredClsCount.ToString();
            lblNClasses.Text = mgr.NCoverdClsCount.ToString();
            lblMethodsPerClass.Text = string.Format("{0:#.##}", mgr.AvgMethodClass);
            lblTime.Text = mgr.FileCreationTime.ToString();


        }
        catch (Exception ex)
        {
        }

    }

    protected void LoadModLevelStastistics(string modName, string strXMLPath)
    {
        try
        {
            aggrProxy = new IsimpleWcfClient();
            mgr = aggrProxy.ParseXmlObject(strXMLPath);
            ststReport = aggrProxy.GetStateticsBymodule(modName, strXMLPath);
            lblCovLines.Text = ststReport.LOC.ToString();
            lblParCovLines.Text = ststReport.PLOC.ToString();
            lblCovBlocks.Text = ststReport.BlocksCov.ToString();
            lblNCLines.Text = ststReport.NCLOC.ToString();
            lblNCBlocks.Text = ststReport.BlocksNt.ToString();
            lblStatsName.Text = ststReport.Name;
            lblCovClasses.Text = ststReport.TotClsCov.ToString();
            lblNClasses.Text = ststReport.TotNClsCov.ToString();
            lblMethodsPerClass.Text = string.Format("{0:#.##}", ststReport.AvgMtdClass);
            lblTime.Text = mgr.FileCreationTime.ToString();
        }
        catch (Exception ex)
        {

        }
    }

    protected void LoadNamesLevelStatistics(string modName, string nsName, string strXMLPath)
    {
        try
        {
            aggrProxy = new IsimpleWcfClient();
            mgr = aggrProxy.ParseXmlObject(strXMLPath);
            ststReport = aggrProxy.GetStateticsByNameSpace(modName, nsName, strXMLPath);
            lblCovLines.Text = ststReport.LOC.ToString();
            lblParCovLines.Text = ststReport.PLOC.ToString();
            lblCovBlocks.Text = ststReport.BlocksCov.ToString();
            lblNCLines.Text = ststReport.NCLOC.ToString();
            lblNCBlocks.Text = ststReport.BlocksNt.ToString();
            lblStatsName.Text = ststReport.Name;
            lblCovClasses.Text = ststReport.TotClsCov.ToString();
            lblNClasses.Text = ststReport.TotNClsCov.ToString();
            lblMethodsPerClass.Text = string.Format("{0:#.##}", ststReport.AvgMtdClass);
            lblTime.Text = mgr.FileCreationTime.ToString();
        }
        catch (Exception ex)
        {

        }
    }
}
